package com.eta.user.controller;

import com.eta.common.utils.Result;
import com.eta.user.mapper.UserAuthMapper;
import com.eta.user.model.dto.UserLoginDto;
import com.eta.user.model.dto.UserRegisterDto;
import com.eta.user.service.UserAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 星河一叶Ck
 * @date 2025/9/2
 * @description 用户权限控制
 */

@Tag(name = "用户认证接口",description = "包含用户注册、登录、密码重置等认证相关接口")
@RestController
@RequestMapping("/auth")
@Slf4j
@RequiredArgsConstructor
public class UserAuthController {
    private final UserAuthService userAuthService;

    /**
     * 用户注册
     *
     * @param userRegisterDto 用户注册信息
     * @return 注册结果
     */
    @Operation(summary = "用户注册", description = "用户注册接口（账号/手机号/邮箱唯一）")
    @PostMapping("/register")
    public Result register(@Valid @RequestBody UserRegisterDto userRegisterDto) {
        userAuthService.register(userRegisterDto);
        return Result.success("注册成功");
    }

    @Operation(summary = "用户登录", description = "用户登录接口")
    @PostMapping("/login")
    public Result login(@Valid @RequestBody UserLoginDto userLoginDto) {
        userAuthService.login(userLoginDto);
        return Result.success("登录成功");
    }

}
